# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Douglas Soares de Andrade <dsa@aur.archlinux.org>

pkgbase=qscintilla
pkgname=(qscintilla-qt5 python-qscintilla-qt5 qscintilla-qt6 python-qscintilla-qt6)
pkgver=2.14.0
pkgrel=2
license=(GPL)
arch=(x86_64)
url='https://www.riverbankcomputing.com/software/qscintilla/intro'
makedepends=(python-pyqt5 qt5-tools python-pyqt6 qt6-tools sip pyqt-builder)
source=(https://www.riverbankcomputing.com/static/Downloads/QScintilla/$pkgver/QScintilla_src-$pkgver.tar.gz)
sha256sums=('449353928340300804c47b3785c3e62096f918a723d5eed8a5439764e6507f4c')

build() {
  cp -r QScintilla_src-$pkgver{,-qt5}

  cd QScintilla_src-$pkgver-qt5/src
  export QMAKEFEATURES=$PWD/src/features/
  qmake-qt5
  make

  cd ../designer
  qmake-qt5 INCLUDEPATH+=../src QMAKE_LIBDIR+=../src
  make

  cd ../Python
  mv pyproject{-qt5,}.toml
  sip-build \
    --no-make \
    --qsci-features-dir ../src/features \
    --qsci-include-dir ../src \
    --qsci-library-dir ../src \
    --api-dir /usr/share/qt/qsci/api/python
  cd build
  make

  cd "$srcdir"/QScintilla_src-$pkgver/src
  export QMAKEFEATURES=$PWD/src/features/
  qmake6
  make

  cd ../designer
  qmake6 INCLUDEPATH+=../src QMAKE_LIBDIR+=../src
  make

  cd ../Python
  mv pyproject{-qt6,}.toml
  sip-build \
    --no-make \
    --qsci-features-dir ../src/features \
    --qsci-include-dir ../src \
    --qsci-library-dir ../src \
    --qmake=/usr/bin/qmake6
  cd build
  make
}

package_qscintilla-qt5() {
  pkgdesc="A port to Qt5 of Neil Hodgson's Scintilla C++ editor class"
  depends=(qt5-base)

  cd QScintilla_src-$pkgver-qt5/src
  make DESTDIR="$pkgdir" INSTALL_ROOT="$pkgdir" install

  cd ../designer
  make DESTDIR="$pkgdir" INSTALL_ROOT="$pkgdir" install
}

package_python-qscintilla-qt5() {
  pkgdesc='Python bindings for QScintilla2'
  depends=(qscintilla-qt5 python-pyqt5)
  replaces=(python-qscintilla-qt5-common)

  cd QScintilla_src-$pkgver-qt5/Python/build
  make INSTALL_ROOT="$pkgdir" install
}

package_qscintilla-qt6() {
  pkgdesc="A port to Qt6 of Neil Hodgson's Scintilla C++ editor class"
  depends=(qt6-base)

  cd QScintilla_src-$pkgver/src
  make DESTDIR="$pkgdir" INSTALL_ROOT="$pkgdir" install

  cd ../designer
  make DESTDIR="$pkgdir" INSTALL_ROOT="$pkgdir" install
}

package_python-qscintilla-qt6() {
  pkgdesc='Python bindings for QScintilla2'
  depends=(qscintilla-qt6 python-pyqt6)

  cd QScintilla_src-$pkgver/Python/build
  make INSTALL_ROOT="$pkgdir" install
}
